package com.springboot.test.service;

import com.springboot.test.domain.User;
import com.springboot.test.enums.ResultEnum;
import com.springboot.test.exception.WebException;
import com.springboot.test.repository.UserRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @name:
 * @desc:
 * @author: qk on 2017/8/12 18:36.
 */
@Service
public class UserService {
    @Autowired
    private UserRepository userRepository;

    public void queryAgeById(Integer id) throws WebException {
        User user = userRepository.findOne(id);
        Integer age = user.getAge();
        if (18 <= age && 25 > age) {
            throw new WebException(ResultEnum.YOUNG);
        } else if (25 <= age && 35 > age) {
            throw new WebException(ResultEnum.MIDDLE);
        } else {
            throw new WebException(ResultEnum.OLD);
        }
    }

}
